package com.crm.dao.before_sale;

import com.crm.pojo.PlanDetail;
import com.crm.pojo.SalePlan;
import com.crm.vo.SalePlanDetailsVO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

public interface PlanDetailsDAO extends CrudRepository<PlanDetail,Long>, JpaSpecificationExecutor<PlanDetail> { /**
 * 获取一个计划下的明细列表
 * @param salePlan
 * @return
 */
@Query("select new com.crm.vo.SalePlanDetailsVO(pl,pr,cl.cname,us.uname) from PlanDetail pl,ProductionDetail pr,ClientInfo cl,Userinfo us" +
        " where cl.cid=pl.clientId and us.uId=pl.userId and pr.pid=pl.salePlanId  and pl.planDetailIsDel='否' and pl.salePlan=?1")
public List<SalePlanDetailsVO> getPlanDetailsListBySalePlanId(SalePlan salePlan);

    /**
     * 删除销售计划对应的计划明细
     */
    @Query(nativeQuery = true ,value ="update PLAN_DETAIL set PLAN_DETAIL_IS_DEL = '是' where SALE_DET_ID=?1")
    @Modifying
    public void deleteSalePlanDetails(Long saleDetId);



}
